package com.jizhi.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jizhi.entity.History;
import com.jizhi.service.HistoryService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 罗兆良
 * @since 2020-11-16
 */
@RestController
@RequestMapping("/history")
public class HistoryController {
    private static final Logger logger = LoggerFactory.getLogger(HistoryController.class);
    @Resource
    private HistoryService historyService;


    @ApiOperation(value = "根据病人id查询病人病历", notes = "根据病人id查询病人病历")
    @GetMapping("/getAllHistoryPage/{bid}")
    public List<History> getAllHistoryPage(@PathVariable("bid")Integer pid,int current, Model model) {
        Page<Object> page = new Page<>(current, 2);
        List<History> doctorList = historyService.selectPage(page,pid);
        logger.info("查询成功");
        return doctorList;
    }

    @ApiOperation(value = "添加病人病历", notes = "添加病人病历")
    @GetMapping("/getAddHistory")
    public String getAddHistory(History history) {
        int addHistory = historyService.getAddHistory(history);
        if (addHistory>0){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }

}

